<?php
declare (strict_types = 1);

namespace app\wx\controller;
use app\common\traits\Jwt;
class Auth extends WxBase
{
    use Jwt;
    protected function initialize()
    {
        $this->model = new \app\auth\model\Member;
        parent::initialize();
    }
    /**
     * 返回格式实例
     * 'openid' => 'oPWpMwvcpfYMnGL-HEHm3Dds78wA',
     * 'nickname' => 'M🐶',
     * 'sex' => 1,
     * 'language' => 'zh_CN',
     * 'city' => '太原',
     * 'province' => '山西',
     * 'country' => '中国',
     * 'headimgurl' => 'http://thirdwx.qlogo.cn/mmopen/vi_32/PiajxSqBRaEIW9YUiahtJBYPqPyehrfmyU0qoFdHUyur6PfZlUgCqUEibCMVibtTGficTiboCsWnPackAGIwNko7Niaog/132',
     * 'privilege' => 
     * array (
     * ),
     */
    public function login() {
        $snsapi_userinfo = $this->app->oauth->user();
        $userinfo = [];
        $userid = $this->model->updateFormWx($snsapi_userinfo);
        if(!$userid){ return json('请关注公众号！',500);}
        $userinfo['userid']= $userid;
        $userinfo['avatar'] = $snsapi_userinfo->getAvatar();
        $userinfo['nickname'] = $snsapi_userinfo->getName();
        $userinfo['openid'] = $snsapi_userinfo->getId();
        $userinfo['token'] = $this->issuing_token($userid);
        return json($userinfo);
    }
    /**
     * 返回js sdk的配置文件
     *
     * @return void
     */
    public function jssdkconfig()
    {
        $jsApiList = ['updateAppMessageShareData','updateTimelineShareData', 'onMenuShareAppMessage', 'onMenuShareTimeline'];
        $this->app->jssdk->setUrl($_SERVER['HTTP_REFERER']);
        $res = $this->app->jssdk->buildConfig($jsApiList,false);
        echo $res;exit;
    }
}
